#include <iostream>
#include <map>
using namespace std;

bool is_prime(int s)
{
    for(int i=2;i<s;i++){
        if(s%i==0){
            return false;
        }
    }
    return true;
}


int main() 
{
    bool flag = false;
    string s;
    string word = "";
    string number = "";
    int a=0,u=0;
    
    map <string, string> digits = {
        {"zero","0"},
        {"one","1"},
        {"two","2"},
        {"three","3"},
        {"four","4"},
        {"five","5"},
        {"six","6"},
        {"seven","7"},
        {"eight","8"},
        {"nine","9"}
    };
    
    getline(cin, s);
    
    
    int index = 0;
    while (index < (int)s.size()) 
    {
        while (s[index] == ' ')
        {
                index ++;
        }
          
        word = "";
        while (index < (int)s.size() and s[index] != ' ')
        {
            word = word  + s[index];
            index ++;
            }
            if(digits.contains(word) ){
                number = number + digits[word];
            }
            else{
                flag = true;
            }
        }
        
    int n = stoi(number);
    for(int k=n+1;k>n;k++){
        if(is_prime(k)){
            a=k;
            break;
        }
    }
    for(int o=n-1;o<n;o--){
        if(is_prime(o)){
            u=o;
            break;
        }
    }
    if(flag==true){
        cout << "Wrong input"<<endl;
        
    }
    else if(n-u>a-n){
        cout << a << endl;
    }
    else if(a-n>n-u){
        cout << u << endl;
    }
    else if(a-n==n-u){
        if (a<u){
            cout<<a<<endl;
        }
        else{
            cout<<u<<endl;
        }
    
    }
    }







